package com.ys.controller.web.base;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.entity.base.TpAmazonRegion;
import com.ys.service.sys.CommonApiService;

@Controller
@RequestMapping("/web/base/tpAmazonRegion")
public class WebTpAmazonRegionController {
	
	@Autowired
	private CommonApiService<TpAmazonRegion> commonApiService;
	
	/*
	 * 新增
	 */
	@RequiresPermissions("tpAmazonRegion:add")
	@GetMapping("/toAdd")
	public String toAdd(Model model){
		try {
			return commonApiService.toAdd(model, new TpAmazonRegion(), MenuId.TP_AmazonRegion, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 修改
	 */
	@RequiresPermissions("tpAmazonRegion:edit")
	@GetMapping("/toEdit")
	public String toEdit(Model model, Long id){
		
		Map<String, Object> extraParam = new TpAmazonRegion().setId(id)
				.addLeftJoin("TB_Platform B ON B.Code = A.PlatformCode")
				.addField("B.Name platformName")
				.queryFirstMap();

		try {
			return commonApiService.toEdit(model, id, new TpAmazonRegion(), MenuId.TP_AmazonRegion, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 详情页
	 */
	@RequiresPermissions("tpAmazonRegion:view")
	@GetMapping("/toDetail")
	public String toDetail(Model model, Long id){
		
		Map<String, Object> extraParam = new TpAmazonRegion().setId(id)
				.addLeftJoin("TB_Platform B ON B.Code = A.PlatformCode")
				.addField("B.Name platformName")
				.queryFirstMap();

		try {
			return commonApiService.toDetail(model, id, new TpAmazonRegion(), MenuId.TP_AmazonRegion, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
}
